package com.jasperframework.boot.common.utils;

import com.google.common.collect.Lists;
import org.apache.commons.collections4.ListUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

/**
  * <p>  </p>
  *
  * @site https://miliqkdoc.motopa.cn/
  * @author daizhao
  * @date 2022/12/12 12:12
  */
public class SpliteListUtil {

    /**
     * 使用guava分割 list
     * @param list
     * @param size
     * @return
     */
    public static <T> List<List<T>> useGuavaPartition(List<T> list, int size){
        return Lists.partition(list, size);
    }

    /**
     * 使用apache分割 list
     * @param list
     * @param size
     * @return
     */
    public static <T> List<List<T>> useApachePartition(List<T> list, int size){
        return ListUtils.partition(list, size);
    }


    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        IntStream.rangeClosed(1,1990).boxed().forEach(i->
                list.add(i)
        );
        System.out.println("list = " + list);

        List<List<Integer>> list1 = useGuavaPartition(list, 200);

        List<List<Integer>> list2 = useApachePartition(list, 200);

        //list1.forEach(i-> System.out.println("i = " + i));

        list1.forEach(i-> System.out.println("i = " + i));
    }
}
